package tomcatDemo;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TestClient {
	public static void main(String[] args) throws Exception {
		Socket socket = null;
		InputStream is = null;
		OutputStream ops = null;
		try {
			 //1_建立socket对象
			 socket = new Socket("www.itcast.cn", 80);
			 //2_获取输出流对象
			 is = socket.getInputStream();
			 //3_获取输入流对象
			 ops = socket.getOutputStream();
			 ops.write("GET /subject/about/index.html HTTP/1.1\n".getBytes());
			 ops.write("HOST:www.itcast.cn\n".getBytes());
			 ops.write("\n".getBytes());
			 int i = is.read();
			 while(i!=-1){
				 System.out.print((char)i);
				 i = is.read();
			 }
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			if(null != is){
				is.close();
				is = null;
			}
			if(null != ops){
				ops.close();
				ops = null;
			}
			if(null != socket){
				socket.close();
				socket = null;
			}
		} 
	}
	
}
